#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
	int N, target;
	cin >> N >> target;
	vector<int>nums;
	for (int i = 0; i < N; i++) {
		int x;
		cin >> x;
		nums.push_back(x);
	}
	long long count = 0;
	sort(nums.begin(), nums.end());
	for (int i = 0; i < N; i++) {
		count+= upper_bound(nums.begin() + i, nums.end(), target + nums[i])-lower_bound(nums.begin()+i, nums.end(), target + nums[i]);
	}
	cout << count;
	return 0;
}